package com.ireadyit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.ireadyit.domain.Ticket;
import com.ireadyit.service.ITicketService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 原浩伟
 * @description 车票Controller
 * @date 2021-05-14 9:40
 */
@RestController
@ApiOperation("订单模块")
public class TicketController {

    @Autowired
    private ITicketService ticketService;

    /**
     * @description 使用Mybatis Plus进行分页测试
     * @param page
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page
     * @author 原浩伟
     * @date 2021-05-14 16:16
     */
    @ApiOperation(value = "使用MybatisPlus分页查询车票信息", httpMethod = "POST")
    @RequestMapping("/mpPageTest")
    public Page mpPageTest(@RequestBody @ApiParam(name = "分页对象", value = "传入json格式", required = true) Page page){
        return ticketService.findTicketPage(page);
    }

    /**
     * @description 使用Mybatis进行分页测试
     * @param size
	 * @param current
     * @return com.github.pagehelper.PageInfo<com.ireadyit.domain.Ticket>
     * @author 原浩伟
     * @date 2021-05-14 16:19
     */
    @ApiOperation(value = "使用Mybatis分页查询车票信息", httpMethod = "POST")
    @RequestMapping("/mybatisPageTest")
    public PageInfo<Ticket> mybatisPage(@RequestParam Integer size, @RequestParam Integer current){
        Page page = new Page();
        page.setCurrent(current);
        page.setSize(size);
        PageInfo<Ticket> ticketPageUseMybatis = ticketService.findTicketPageUseMybatis(page);
        return ticketPageUseMybatis;
    }
}
